package com.chzc.fm.duotin.ui.more;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.DrawableWrapper;
import android.os.Environment;
import android.provider.ContactsContract;
import android.view.Display;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;


import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.ui.other.BaseActivity;
import com.chzc.fm.duotin.ui.other.BaseFragment;
import com.chzc.fm.duotin.utils.DuotinTask;
import com.nostra13.universalimageloader.utils.L;

import java.io.File;

/**
 * Created by BillSinla on 2016/6/23.
 */
public class MoreFragment extends BaseFragment  {

    private boolean ischeck=false;
    private TextView textView1,textView2;
    private ImageView suspendswitch,Record_payPosition;
    private LinearLayout line1,line2,line3,line4,line5,line6,line7;
    private ImageView checkchange1,checkchange2,checkchange3,checkchange4,checkchange5,checkchange6,checkchange7;
    private LinearLayout downloadpath,clearCache,carlistenbaby,Feedback,recommendApp,newversion,officialwechat,aboutUS;
    private ImageView escdialog;
    private Button yes,no,clean,unclean;
    private LinearLayout versionyes,linner_Record_payPosition,linner_suspendswitch;
    @Override
    protected int getLayoutId() {
        return R.layout.fragment_more;
    }

    @Override
    protected void initViews() {

        textView1=(TextView)root.findViewById(R.id.textView1);
        textView2=(TextView)root.findViewById(R.id.textView2);
        linner_suspendswitch=(LinearLayout)root.findViewById(R.id.linner_suspendswitch) ;
        linner_Record_payPosition=(LinearLayout)root.findViewById(R.id.linner_Record_payPosition);
        suspendswitch=(ImageView) root.findViewById(R.id.suspendswitch);
        Record_payPosition=(ImageView) root.findViewById(R.id.Record_payPosition);
        downloadpath=(LinearLayout)root.findViewById(R.id.downloadpath);
                clearCache=(LinearLayout)root.findViewById(R.id.clearCache);
        carlistenbaby=(LinearLayout)root.findViewById(R.id.carlistenbaby);
                Feedback=(LinearLayout)root.findViewById(R.id.Feedback);
        recommendApp=(LinearLayout)root.findViewById(R.id.recommendApp);
                newversion=(LinearLayout)root.findViewById(R.id.newversion);
        officialwechat=(LinearLayout)root.findViewById(R.id.officialwechat);
                aboutUS=(LinearLayout)root.findViewById(R.id.aboutUS);
        aboutUS=(LinearLayout)root.findViewById(R.id.aboutUS);

        textView1.setOnClickListener(new MyOnclick());
        textView2.setOnClickListener(new MyOnclick());
        suspendswitch.setOnClickListener(new MyOnclick());
        Record_payPosition.setOnClickListener(new MyOnclick());
        downloadpath.setOnClickListener(new MyOnclick());
        clearCache.setOnClickListener(new MyOnclick());
        carlistenbaby.setOnClickListener(new MyOnclick());
        Feedback.setOnClickListener(new MyOnclick());
        recommendApp.setOnClickListener(new MyOnclick());
        newversion.setOnClickListener(new MyOnclick());
        officialwechat.setOnClickListener(new MyOnclick());
        aboutUS.setOnClickListener(new MyOnclick());
        linner_suspendswitch.setOnClickListener(new MyOnclick());
        linner_Record_payPosition.setOnClickListener(new MyOnclick());

    }

  class MyOnclick implements View.OnClickListener {

      public void onClick(View view) {
          switch (view.getId()) {
              case R.id.recommendApp: {
                  Intent intent = new Intent(getActivity(), RecommendApp.class);
                  startActivity(intent);
                  break;
              }
              case R.id.textView1:{
                  LayoutInflater inflater = LayoutInflater.from(getActivity());
                  View v= inflater.inflate(R.layout.alert_dialog,null);
                  final Dialog builder=new Dialog (getActivity(),R.style.dialog);
                  builder.setContentView(v);
                  final Window dialogWindow = builder.getWindow();
                  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                  dialogWindow.setGravity(Gravity.CENTER_VERTICAL |Gravity.CENTER_HORIZONTAL);
                  lp.x =0; // 新位置X坐标
                  lp.y =0; // 新位置Y坐标
                   lp.width = 450; // 宽度
//                  lp.height = 600; // 高度
                 // lp.alpha = 0.7f; // 透明度

                  dialogWindow.setBackgroundDrawable(new BitmapDrawable());
                  dialogWindow.setAttributes(lp);
         //点击弹出框外围退出
                  builder.setCanceledOnTouchOutside(true);
                  builder.setCancelable(true);

                  builder.show();
                  checkchange1=(ImageView)v.findViewById(R.id.checkchange1);
                          checkchange2=(ImageView)v.findViewById(R.id.checkchange2);
                  checkchange3=(ImageView)v.findViewById(R.id.checkchange3);
                          checkchange4=(ImageView)v.findViewById(R.id.checkchange4);
                  checkchange5=(ImageView)v.findViewById(R.id.checkchange5);
                          checkchange6=(ImageView)v.findViewById(R.id.checkchange6);
                  checkchange7=(ImageView)v.findViewById(R.id.checkchange7);
                 line1=(LinearLayout)v.findViewById(R.id.line1);
                  escdialog=(ImageView)v.findViewById(R.id.escdialog) ;
                  escdialog.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          //关闭对话框
                          builder.dismiss();
                      }
                  });
                  line1.setOnClickListener(new View.OnClickListener() {

                      public void onClick(View view) {
                          checkchange2.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange3.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange4.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange5.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange6.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange7.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange1.setImageResource(R.drawable.ic_storage_selected);
                          builder.dismiss();
                      }

                  });

                  line2=(LinearLayout)v.findViewById(R.id.line2);
                  line2.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          checkchange1.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange3.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange4.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange5.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange6.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange7.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange2.setImageResource(R.drawable.ic_storage_selected);
                          builder.dismiss();
                      }
                  });
                  line3=(LinearLayout)v.findViewById(R.id.line3);
                  line3.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          checkchange2.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange1.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange4.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange5.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange6.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange7.setImageResource(R.drawable.ic_storage_unseleted);
                          Toast.makeText(getActivity(),"333333333",Toast.LENGTH_LONG).show();
                          checkchange3.setImageResource(R.drawable.ic_storage_selected);
                      }
                  });
                  line4=(LinearLayout)v.findViewById(R.id.line4);
                  line4.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          checkchange2.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange3.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange1.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange5.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange6.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange7.setImageResource(R.drawable.ic_storage_unseleted);
                          Toast.makeText(getActivity(),"444444444",Toast.LENGTH_LONG).show();
                          checkchange4.setImageResource(R.drawable.ic_storage_selected);
                      }
                  });
                  line5=(LinearLayout)v.findViewById(R.id.line5);
                  line5.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          checkchange2.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange3.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange4.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange1.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange6.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange7.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange5.setImageResource(R.drawable.ic_storage_selected);
                          Toast.makeText(getActivity(),"55555555",Toast.LENGTH_LONG).show();
                      }
                  });
                  line6=(LinearLayout)v.findViewById(R.id.line6);
                  line6.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          checkchange2.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange3.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange4.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange5.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange1.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange7.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange6.setImageResource(R.drawable.ic_storage_selected);
                          Toast.makeText(getActivity(),"66666666666",Toast.LENGTH_LONG).show();
                      }
                  });
                  line7=(LinearLayout)v.findViewById(R.id.line7);
                  line7.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          checkchange2.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange3.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange4.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange5.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange6.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange1.setImageResource(R.drawable.ic_storage_unseleted);
                          checkchange7.setImageResource(R.drawable.ic_storage_selected);
                          Toast.makeText(getActivity(),"777777777",Toast.LENGTH_LONG).show();
                      }
                  });
                  break;
              }
              case R.id.textView2:{
                  LayoutInflater inflater= LayoutInflater.from(getActivity());
                  View v=inflater.inflate(R.layout.flow_dialog,null);
                  final Dialog builder=new Dialog (getActivity(),R.style.dialog);
                  builder.setContentView(v);
                  final Window dialogWindow = builder.getWindow();
                  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                  dialogWindow.setGravity(Gravity.CENTER_VERTICAL |Gravity.CENTER_HORIZONTAL);
                  lp.x =0; // 新位置X坐标
                  lp.y =0; // 新位置Y坐标
                  lp.width =450; // 宽度
//                  lp.height = 600; // 高度
                  // lp.alpha = 0.7f; // 透明度

                  dialogWindow.setBackgroundDrawable(new BitmapDrawable());
                  dialogWindow.setAttributes(lp);
                  //点击弹出框外围退出
                  builder.setCanceledOnTouchOutside(true);
                  builder.setCancelable(true);

                  builder.show();
                  yes=(Button)v.findViewById(R.id.yes);
                  no=(Button)v.findViewById(R.id.no);
                  yes.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                         builder.dismiss();
                      }
                  });
                  no.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          builder.dismiss();
                      }
                  });


                  break;
              }
              case R.id.linner_suspendswitch:{
                    if(ischeck==true)
                    {
                        suspendswitch.setBackgroundResource(R.drawable.bg_toggle_check_off);
                   ischeck=false;
                     }
                  else if(ischeck==false){
                      suspendswitch.setBackgroundResource(R.drawable.bg_toggle_check_on);
                      ischeck=true;
                  }
                  break;
              }
              case R.id.linner_Record_payPosition:{
                  if(ischeck==true)

                  {
                      Record_payPosition.setBackgroundResource(R.drawable.bg_toggle_check_off);
                      ischeck=false;
                  }
                  else if(ischeck==false){
                      Record_payPosition.setBackgroundResource(R.drawable.bg_toggle_check_on);
                      ischeck=true;
                  }
                  break;
              }
              case R.id.downloadpath:{
                  Intent intent=new Intent(getActivity(),Downloadactivity.class);
                  startActivity(intent);
                  break;
              }
              case R.id.clearCache:{
//                  new AlertDialog.Builder(getActivity())
//                          .setTitle("确定清理缓存吗？")
//                          .setMessage("清除缓存，可以增加手机内存；再次收听，需要重新消耗流量")
//                          .setPositiveButton("取消",new DialogInterface.OnClickListener() {
//                              @Override
//                              public void onClick(DialogInterface dialog,int which) {
//                                     DataCleanManager dataCleanManager=new DataCleanManager();
//
//                              }
//                          })
//                          .setNegativeButton("确定",new DialogInterface.OnClickListener() {
//                              @Override
//                              public void onClick(DialogInterface dialog,int which) {
//                                  // TODO Auto-generated method stub
//
//                              }
//                          })
//                          .show();
                  LayoutInflater inflater=LayoutInflater.from(getActivity());
                  View v=inflater.inflate(R.layout.cache_dialog,null);
                  final Dialog dialog=new Dialog(getActivity(),R.style.dialog);
                  dialog.setContentView(v);
                  Window dialogwindow=dialog.getWindow();
                  final Window dialogWindow = dialog.getWindow();
                  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                  dialogWindow.setGravity(Gravity.CENTER_VERTICAL |Gravity.CENTER_HORIZONTAL);
                  lp.x =0; // 新位置X坐标
                  lp.y =0; // 新位置Y坐标
                  lp.width = 450; // 宽度
//                  lp.height = 600; // 高度
                  // lp.alpha = 0.7f; // 透明度

                  dialogWindow.setBackgroundDrawable(new BitmapDrawable());
                  dialogWindow.setAttributes(lp);
                  //点击弹出框外围退出
                  dialog.setCanceledOnTouchOutside(true);
                  dialog.setCancelable(true);

                  dialog.show();
                  clean=(Button)v.findViewById(R.id.clean);
                  unclean=(Button)v.findViewById(R.id.unclean);
                  clean.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          dialog.dismiss();
                      }
                  });
                  unclean.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          dialog.dismiss();
                      }
                  });


                  break;
              }
              case R.id.carlistenbaby:{
                  Intent intent=new Intent(getActivity(),Carlistenbaby.class);
                  startActivity(intent);
                  break;
              }
              case R.id.Feedback:{
                  Intent intent=new Intent(getActivity(),Feedback.class);
                  startActivity(intent);
                  break;
              }
              case R.id.newversion:{
//                  new AlertDialog.Builder(getActivity())
//                          .setTitle("系统提示")
//                          .setMessage("您当前已是最新版本")
//                          .setPositiveButton("确定", null)
//                          .show();
                  LayoutInflater inflater=LayoutInflater.from(getActivity());
                View v= inflater.inflate(R.layout.newversion_dialog,null);
                  final Dialog dialog=new Dialog(getActivity(),R.style.dialog);
                  dialog.setContentView(v);
                  Window dialogwindow=dialog.getWindow();
                  final Window dialogWindow = dialog.getWindow();
                  WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                  dialogWindow.setGravity(Gravity.CENTER_VERTICAL |Gravity.CENTER_HORIZONTAL);
                  lp.x =0; // 新位置X坐标
                  lp.y =0; // 新位置Y坐标
                  lp.width = 450; // 宽度
//                  lp.height = 600; // 高度
                  // lp.alpha = 0.7f; // 透明度

                  dialogWindow.setBackgroundDrawable(new BitmapDrawable());
                  dialogWindow.setAttributes(lp);
                  //点击弹出框外围退出
                  dialog.setCanceledOnTouchOutside(true);
                  dialog.setCancelable(true);

                  dialog.show();
                versionyes=(LinearLayout)v.findViewById(R.id.versionyes);
                  versionyes.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          dialog.dismiss();
                      }
                  });
                  break;
              }
              case R.id.aboutUS:{
                  Intent intent=new Intent(getActivity(),AboutActivity.class);
                  startActivity(intent);
                  break;

              }
              case R.id.officialwechat:{
                  Intent intent=new Intent(getActivity(),Officialwechat.class);
                  startActivity(intent);
                  break;
              }
              default:    break;
          }
      }
  }

    public void initalertdiolog(){

    }

    @Override
    protected void initEvent() {

    }

    @Override
    protected void initData() {

    }

}
